﻿using System;
using System.Collections.Generic;
//Master for all NPS Page
public class PageBase : System.Web.UI.Page
{
    public PageBase() { }

    protected int getItemID
    {
        get
        {
            return getQueryInt("id");
        }
    }

    protected void AlertNotification(string message)
    {
        string js = "$.jGrowl('" + message + "',{ animateOpen: { height: 'show'}, animateClose: { height: 'hide'},live:10000,position:'bottom-left' });";
        launchScript("jgrowlwarn", js);
    }

    protected void AlertNotification(string message,string title)
    {
        string js = "$.jGrowl('" + message + "',{ header:'"+title+",'animateOpen: { height: 'show'},animateClose: { height: 'hide'},live:10000,position:'bottom-left'});";
        launchScript("jgrowlwarn", js);    
    }

    protected void launchScript(string scriptname,string script)
    {
        if (null != System.Web.UI.ScriptManager.GetCurrent(Page) )
            System.Web.UI.ScriptManager.RegisterClientScriptBlock(this, typeof(string), scriptname, script, true);
        else
            Page.ClientScript.RegisterStartupScript(typeof(string), scriptname, script, true);
    }


    protected int getQueryInt(string name)
    {

        int result = 0;
        try { result = Convert.ToInt32(getQueryString(name)); }
        catch { }
        return result;
    }

    protected List<int> Batch
    {
        get
        {
            List<int> batch = new List<int>();
            batch.Add(2013);
            int current = DateTime.Now.Year;
            int diff = current - 2013;
            if (diff > 0)
            {
                for (int i = 1; i <= diff; i++)
                {
                    batch.Add(2013 + i);
                }
            }
            return batch;
        }
    }

    protected string getQueryString(string name)
    {
        try
        {
            if (!string.IsNullOrEmpty(Request.QueryString[name]))
            {
                return secureString(Request.QueryString[name].ToString());
            }
            else { throw new Exception(); }
        }
        catch { return "nothing"; }
    }

    protected FormMode getMode
    {
        get
        {
            try
            {
                string _sxMode = getQueryString("mode");
                if (!string.IsNullOrEmpty(_sxMode))
                {
                    switch (_sxMode)
                    {
                        case "editor":
                            return FormMode.Editor;
                        default:
                            return FormMode.View;
                    }
                }
                else return FormMode.View;
            }
            catch (Exception p) { return FormMode.View; }
        }
    }

    protected string setStringSecurity(string input)
    {
        return input;//secure(secureString(input));
    }

    protected string secureString(string input)
    {
        return input;// Microsoft.Security.Application.Encoder.JavaScriptEncode(input);
    }

    protected string secure(string input)
    {
        return input;
        // return System.Web.HttpUtility.HtmlDecode(input);
    }
    protected string unsecure(string input)
    {
        return input;
        // return System.Web.HttpUtility.HtmlEncode(input);
    }


    protected static string type_Detractor = "DETRACTOR";
    protected static string type_Promoter = "PROMOTER";
    protected static string type_Passive = "PASSIVE";
}